/*
 * Change Logs:
 * Date           Author       Notes
 * 2020-08-21     chenbin      small mb the first version
 */
#include "rtu_mb_tcp.h"
#include "rtu_mb_utils.h"
#include "config_rtu_mb.h"

/* Builds a TCP request header */
static int _tcp_build_request_header(rtu_mb_t* smb, uint8_t* buff, int slave, int fun, int reg, int num)
{
    return _MODBUS_TCP_PRESET_REQ_LENGTH;
}

/* Builds a TCP response header */
static int _tcp_build_response_header(rtu_mb_t* smb, uint8_t* buff, int slave, int fun)
{
    return _MODBUS_TCP_PRESET_RSP_LENGTH;
}

static int _tcp_check_send_pre(rtu_mb_t* smb, uint8_t* buff, int length)
{
    return 0;
}

static int _tcp_check_wait_request(rtu_mb_t* smb, uint8_t* buff, int length)
{
    return MODBUS_FAIL_CHECK;
}

static int _tcp_check_wait_response(rtu_mb_t* smb, uint8_t* buff, int length)
{
    return MODBUS_FAIL_CHECK;
}

const rtu_mb_core_t _rmb_tcp_core = {.magic = MODBUS_CORE_MAGIC, .type = MODBUS_CORE_TCP, .len_header = _MODBUS_TCP_HEADER_LENGTH, .len_checksum = _MODBUS_TCP_CHECKSUM_LENGTH, .len_adu_max = _MODBUS_TCP_MAX_ADU_LENGTH, .build_request_header = _tcp_build_request_header, .build_response_header = _tcp_build_response_header, .check_send_pre = _tcp_check_send_pre, .check_wait_request = _tcp_check_wait_request, .check_wait_response = _tcp_check_wait_response};
